package org.hqs.nurse.service;

import org.hqs.feign.clients.DepartmentClient;
import org.hqs.feign.pojo.Department;
import org.hqs.nurse.mapper.NurseMapper;
import org.hqs.nurse.pojo.Nurse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class NurseService {

    @Autowired
    private NurseMapper nurseMapper;

    @Autowired
    private DepartmentClient departmentClient;

    public List<Nurse> getAllNurses() {
        List<Nurse> nurses = nurseMapper.getAllNurses();
        for (int i = 0; i < nurses.size(); i++) {
            Nurse nurse =  nurses.get(i);
            // 找出科室
            Department department = departmentClient.getDepartmentById(nurse.getDepartmentId()).getData();
            //放入护士
            nurse.setDepartment(department);
            //设置护士
            nurses.set(i, nurse);
        }
        return nurses;
    }

    public Nurse getNurseById(Long id) {
        Nurse nurse =  nurseMapper.getNurseById(id);

        Department department = departmentClient.getDepartmentById(id).getData();

        nurse.setDepartment(department);

        return nurse;
    }

    public void saveNurse(Nurse nurse) {
        nurseMapper.insertNurse(nurse);
    }

    public void updateNurse(Nurse nurse) {
        nurseMapper.updateNurse(nurse);
    }

    public void deleteNurse(Long id) {
        nurseMapper.deleteNurse(id);
    }
}
